const fp = require('lodash/fp');
const { Maybe, Container } = require('./support');

// 练习1
let maybe = Maybe.of([5, 6, 1]);
let ex1 = functor =>
  functor.map(fp.map(v => ++v));
console.log(ex1(maybe));

// 练习2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do']);
let ex2 = functor =>
  functor.map(fp.first);
console.log(ex2(xs));

// 练习3
let safeProp = fp.curry((x, o) => Maybe.of(o[x]));
let user = { id: 2, name: 'Albert' };
let ex3 = user =>
  safeProp('name', user)
    .map(fp.first)
console.log(ex3(user));

let ex4 = n =>
  Maybe.of(n)
    .map(parseInt)
    ._value;
console.log(ex4('342'));
console.log(ex4());
